<template>
  <div>
    <follow-record :id="clue_id" :tableData="tableData" :limit="limit"
                   :page="page" :total="total" :addDialogFlag="addDialogFlag"
                   @delFollowUpRecord="delClueFollowUpRecord"
                   @getFollowUpRecordList="getClueFollowUpRecordList" @setFollowUpRecord="setClueFollowUpRecord" />
                   <!-- 分页 -->
     <div style="text-align: center;margin-top: 6px;">
       <el-pagination background layout="prev, pager, next" @current-change="pageChange" :current-page="page" :page-size="limit"
         :total="total" />
     </div>
  </div>
</template>

<script>
  import follow_record from "./follow_record_master";
  export default {
    components: {
      "follow-record": follow_record
    },
    props: {
      clue_id: ''
    },
    data() {
      return{
        tableData: [],
        page: 1,
        total: 0,
        limit: 10,//limit还是放这里好
        addDialogFlag: false
      }
    },
    watch: {
      clue_id(val) {
        if(val){
          this.getClueFollowUpRecordList()
        }
      }
    },
    methods: {

      //添加
      async setClueFollowUpRecord(addForm) {
        addForm.clue_id = this.clue_id
        console.log(addForm)
        const res = await this.$api.setClueFollowUpRecord(addForm)
        if(res.data.level=="success"){
          this.$message.success(addForm.id?"编辑成功":"添加成功")
          this.getClueFollowUpRecordList()
        } else {
          this.$message.error(res.data.message)
        }
      },

      //获取列表数据
      async getClueFollowUpRecordList(page){
        let params = {}
        params.customer_clues_id = this.clue_id
        params.limit = this.limit
        if(page){
          params.page = page
        } else{
          params.page = this.page;
        }
        const res = await this.$api.getCustomerServiceRecord(params)
        if(res.data.level=="success"){
          this.tableData = res.data.data
          this.addDialogFlag = !this.addDialogFlag
          this.total = res.data.page_info.total
        } else {
          this.$message.error(res.data.message)
        }
      },
      //分页 pageChange当前页发生改变触发函数
      async pageChange(page) {
        this.page = page
         // window.sessionStorage.setItem("coursePage",this.startpage)
        //调用获取列表的方法
        this.loading = true
        this.getClueFollowUpRecordList()
      },
      //删除数据
      async delClueFollowUpRecord(id){
        let params = {
          id
        }
        const res = await this.$api.delClueFollowUpRecord(params)
        if(res.data.level=="success"){
          this.$message.success(res.data.message)
          this.getClueFollowUpRecordList()
        } else {
          this.$message.error(res.data.message)
        }
      },

    }
  }
</script>

<style scoped>

</style>
